package com.songyang.mqttandothers.common;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.HashMap;
import java.util.List;

/*
给前端返回的json格式数据
 */
public class ResultMapUtil {
    /*
    登录返回结果
     */
    public static HashMap<String, Object> getHashMapLogin(String msg, String code, Integer userId) {
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("msg", msg);
        resultMap.put("code", code);
        resultMap.put("userId", userId);
        if ("1".equals(code)) {
            resultMap.put("icon", 1);
        } else {
            resultMap.put("icon", 3);
        }
        return resultMap;
    }

    public static HashMap<String, Object> success() {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code", 0);
        hashMap.put("msg", "成功");
        return hashMap;
    }

    public static HashMap<String, Object> getGraphHashMap(List<?> time, List<?> value) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code", 0);
        hashMap.put("msg", "成功");
        hashMap.put("total",time.size());
        hashMap.put("time", time);
        hashMap.put("value", value);
        return hashMap;
    }

    public static HashMap<String, Object> fail(String msg) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code", 3);
        hashMap.put("msg", msg);
        return hashMap;
    }

    public static HashMap<String, Object> bind(Integer bindId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code", 0);
        hashMap.put("msg", "");
        hashMap.put("deviceId", bindId);
        return hashMap;
    }

    /*
    分页查询结果
     */
    public static HashMap<String, Object> getHashMapMysqlPage(IPage<?> list) {
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", 0);
        resultMap.put("msg", "");
        resultMap.put("count", list.getTotal());
        resultMap.put("data", list.getRecords());
        return resultMap;
    }

    /*
分页查询结果
 */
    public static HashMap<String, Object> getHashMapMysqlPage(List<?> list) {
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", 0);
        resultMap.put("msg", "");
        resultMap.put("count", list.size());
        resultMap.put("data", list);
        return resultMap;
    }

    public static HashMap<String, Object> getHashMapClientId(Integer id) {
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", 0);
        resultMap.put("msg", "");
        resultMap.put("clientId", id);

        return resultMap;
    }

    /*
    异常信息统一处理
     */
    public static HashMap<String, Object> getHashMapException(Exception e) {
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", 0);
        resultMap.put("msg", e.getMessage());
        return resultMap;
    }


}
